home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Shaders / RCShaders / RCSlideProjector.sl < prev    next >
Encoding:
Text File  |  1995-03-22  |  1.3 KB  |  44 lines

  1.  
  2. /*
  3.  *  slideprojector(): Cast a texture map into a scene as a light source
  4.  */
  5. light
  6. RCSlideProjector(    
  7.     float    fieldofview=PI/32;
  8.     point    from        = (8, -4, 10),
  9.         to        = (0,0,0),
  10.         up        = point "eye" (0,1,0);
  11.     string    slidename     = "",
  12.         shadowname      = "" )
  13. {
  14.     uniform point    relT,     /* normalized direction vector */
  15.             relU,     /* "vertical" perspective of surface point */
  16.             relV;    /* "horizontal" perspective of surface point */
  17.     uniform float spread = 1/tan(fieldofview/2); /* spread of "beam" */
  18.     float    Pt,         /* projection of Ps on relT (distance of 
  19.                    surface point along light direction)    */
  20.         Pu,         /* projection of Ps on relU */
  21.          Pv,         /* projection of Ps on relU */
  22.          sloc, tloc;    /* perspected surface point */
  23.  
  24.     /* Initialize uniform variables for perspective */
  25.     relT = normalize(to - from);
  26.     relU = relT ^ up;
  27.     relV = normalize(relT ^ relU);
  28.     relU = relV^relT;
  29.  
  30.     illuminate(from, relT, atan(sqrt(2)/spread)) {
  31.         L =  Ps - from;    /* direction of light source from surf. point */
  32.         Pt = L.relT;    /* coordinates of Ps along relT, relU, relV */
  33.         Pu = L.relU;
  34.         Pv = L.relV;
  35.         sloc = spread*Pu/Pt;    /* perspective divide    */
  36.         tloc = spread*Pv/Pt;
  37.         sloc = sloc*.5 + .5;    /* correction from [-1,1] to [0,1] */
  38.         tloc  = tloc*.5 + .5;
  39.         Cl = color texture(slidename, sloc,tloc);
  40.         if( shadowname != "" )
  41.             Cl *= 1-shadow(shadowname, Ps);
  42.     }
  43. }
  44.